package com.mind.adjust.service.impl;

import com.mind.customer.mapper.AjAttachTypeMapper;
import com.mind.customer.mapper.AjTicketTypeMapper;
import com.mind.customer.utils.CateUtils;
import com.mind.system.domain.AjAttachType;
import com.mind.adjust.service.AjAttachTypeService;
import com.mind.system.domain.AjTicketType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import jakarta.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;


/**
 * 附件分类(AjAttachType)表服务实现类
 *
 * @author makejava
 * @since 2024-07-11 17:18:45
 */
@Service("attachTypeService")
public class AjAttachTypeServiceImpl implements AjAttachTypeService {
    @Autowired
    private AjAttachTypeMapper attachTypeMapper;

    @Resource
    private AjTicketTypeMapper ticketTypeMapper;

    @Resource
    private CateUtils cateUtils;

    /**
     * 查询附件分类信息集合
     * 
     * @param attachType 附件分类信息
     * @return 附件分类信息集合
     */
    @Override
    public List<AjAttachType> selectAttachTypeList(AjAttachType attachType)
    {

        List<AjAttachType> ajAttachTypes = attachTypeMapper.selectAttachTypeList(attachType);
        for(AjAttachType ajAttachType: ajAttachTypes){
            ajAttachType.setTicketType(cateUtils.getTicketTypeName(ajAttachType.getTicketType()));
        }
        return ajAttachTypes;
    }

    /**
     * 通过附件分类ID查询附件分类信息
     * 
     * @param attachTypeId 附件分类ID
     * @return 角色对象信息
     */
    @Override
    public AjAttachType selectAttachTypeById(Long attachTypeId)
    {
        return attachTypeMapper.selectAttachTypeById(attachTypeId);
    }

    /**
     * 删除附件分类信息
     * 
     * @param attachTypeId 附件分类ID
     * @return 结果
     */
    @Override
    public int deleteAttachTypeById(Long attachTypeId)
    {
        return attachTypeMapper.deleteAttachTypeById(attachTypeId);
    }

    /**
     * 批量删除附件分类信息
     * 
     * @param attachTypeIds 需要删除的附件分类ID
     * @return 结果
     */
    @Override
    public int deleteAttachTypeByIds(Long[] attachTypeIds)
    {
        return attachTypeMapper.deleteAttachTypeByIds(attachTypeIds);
    }

    /**
     * 新增保存附件分类信息
     * 
     * @param attachType 附件分类信息
     * @return 结果
     */
    @Override
    public int insertAttachType(AjAttachType attachType)
    {
        return attachTypeMapper.insertAttachType(attachType);
    }

    /**
     * 修改保存附件分类信息
     * 
     * @param attachType 附件分类信息
     * @return 结果
     */
    @Override
    public int updateAttachType(AjAttachType attachType)
    {
        return attachTypeMapper.updateAttachType(attachType);
    }
    
    /**
     * 批量插入
     *
     * @param attachTypeList 附件类型信息
     * @return 结果
     */
    @Override
    public int batchInsert(List<AjAttachType> attachTypeList) {
        int size = 0;
        for(AjAttachType attachType: attachTypeList) {
            if (attachTypeMapper.selectAttachTypeByName(attachType.getName()) == null){
                attachTypeMapper.insertAttachType(attachType);
                size ++;
            }
        }
        return size;
    }
}
